/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.fb.FreeBusy;
/*    */ import com.zimbra.cs.fb.WorkingHours;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Iterator;
/*    */ import java.util.LinkedHashMap;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetWorkingHours
/*    */   extends GetFreeBusy
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 38 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 39 */     Account authAcct = getAuthenticatedAccount(zsc);
/* 40 */     boolean asAdmin = zsc.isUsingAdminPrivileges();
/*    */     
/* 42 */     long rangeStart = request.getAttributeLong("s");
/* 43 */     long rangeEnd = request.getAttributeLong("e");
/* 44 */     validateRange(rangeStart, rangeEnd);
/*    */     
/* 46 */     String idParam = request.getAttribute("id", null);
/* 47 */     String nameParam = request.getAttribute("name", null);
/*    */     
/* 49 */     Provisioning prov = Provisioning.getInstance();
/* 50 */     Map<String, String> idMap = new LinkedHashMap();
/* 51 */     if (idParam != null) {
/* 52 */       String[] idStrs = idParam.split(",");
/* 53 */       for (String idStr : idStrs) {
/* 54 */         idMap.put(idStr, idStr);
/*    */       }
/*    */     }
/* 57 */     if (nameParam != null) {
/* 58 */       String[] nameStrs = nameParam.split(",");
/* 59 */       for (String nameStr : nameStrs) {
/* 60 */         Account acct = prov.get(Key.AccountBy.name, nameStr);
/* 61 */         String idStr = null;
/* 62 */         if (acct != null) {
/* 63 */           idStr = acct.getId();
/*    */         }
/* 65 */         idMap.put(nameStr, idStr);
/*    */       }
/*    */     }
/*    */     
/* 69 */     Element response = getResponseElement(zsc);
/* 70 */     for (Iterator<Map.Entry<String, String>> entryIter = idMap.entrySet().iterator(); entryIter.hasNext();) {
/* 71 */       Map.Entry<String, String> entry = (Map.Entry)entryIter.next();
/* 72 */       String idOrName = (String)entry.getKey();
/* 73 */       String acctId = (String)entry.getValue();
/* 74 */       Account acct = acctId != null ? prov.get(Key.AccountBy.id, acctId) : null;
/*    */       FreeBusy workHours;
/* 76 */       FreeBusy workHours; if (acct != null) { String name;
/*    */         String name;
/* 78 */         if (!idOrName.equalsIgnoreCase(acctId)) {
/* 79 */           name = idOrName;
/*    */         } else
/* 81 */           name = acct.getName();
/* 82 */         workHours = WorkingHours.getWorkingHours(authAcct, asAdmin, acct, name, rangeStart, rangeEnd);
/*    */       } else {
/* 84 */         workHours = FreeBusy.nodataFreeBusy(idOrName, rangeStart, rangeEnd);
/*    */       }
/* 86 */       ToXML.encodeFreeBusy(response, workHours);
/*    */     }
/* 88 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/GetWorkingHours.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */